<?php

namespace brand\components;

use brand\logic\BrandHelper;

class Rate extends Component
{
    public function _init()
    {
        $this->component = 'rate';
    }

    /**
     * 创建Curd表单
     * @param $field
     * @param $props
     */
    public function DbToCurd($field,$props = [])
    {
        return \brand\Brand::Builder()->form_props($props)->form_method('rate')->search_condition('=');
    }


    public function buildConfigColumn($tableConfigValue, $curd_method = 'curd_method')
    {


        $options['max'] = \brand\Brand::Builder('最大值','number')->build();
        $options['void-color'] = \brand\Brand::Builder('未选中的颜色','color')->build();
        $options['color'] = \brand\Brand::Builder('选中的颜色','color')->build();

        $cloumn = \brand\Brand::Builder('日期类型','arrays')
            ->form_options([$options])
            ->form_props( [
                'append'    =>  $curd_method != 'curd_method'
            ])
            ->form_visible([['prop' => $curd_method, 'value' => 'Rate']])
            ->build();



        $props = $tableConfigValue['form']['props'] ?? [];
        if (!isset($props['void-color']) || !$props['void-color']){
            $props['void-color'] = '#C6D1DE';
        }
        if (!isset($props['colors']) || !$props['colors']){
            $props['color'] = '#F7BA2A';
        }else{
            $props['color'] = $props['colors'][0] ?? '#F7BA2A';
        }
        if (!isset($props['max']) || !$props['max']){
            $props['max'] = 5;
        }


        $values[] = $props;

        return ['column' => $cloumn,'value' => $values];
    }

    public function methodFormConf($form,$table,$params)
    {
        $param = $params['param'][0] ?? [];

        $props['void-color'] = $param['void-color'] ?? '#C6D1DE';
        $colors = $param['color'] ?? '#F7BA2A';
        $props['colors'] = [$colors,$colors,$colors];
        $props['max'] = $param['max'] ?? 5;

        $form['props'] = $props;


        return [$form,$table];
    }

}